package mvc_generator.generator.car.jsf;

import com.google.common.base.Objects;
import java.util.ArrayList;
import mvc_generator.generator.MVCGeneratorGeneratorUtils;
import mvc_generator.mVCGenerator.AssignedField;
import mvc_generator.mVCGenerator.Form;
import mvc_generator.mVCGenerator.ModelMVC;
import mvc_generator.mVCGenerator.View;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.xbase.lib.StringExtensions;

@SuppressWarnings("all")
public class ViewGenerator {
  public void generate(final View view, final IFileSystemAccess fsa) {
    int i = 0;
    ModelMVC modelMVCContainer = MVCGeneratorGeneratorUtils.findModelMVCContainer(view);
    CharSequence fileContent = null;
    boolean _equals = Objects.equal(modelMVCContainer, null);
    if (_equals) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("@GenerationError: ModelMVC container not found for this view");
      fileContent = _builder;
      if (true) {
        ArrayList<String> _arrayList = new ArrayList<String>();
        String _string = _arrayList.toString();
        String _plus = (fileContent + _string);
        fileContent = _plus;
      }
    } else {
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("<!DOCTYPE html PUBLIC ");
      _builder_1.newLine();
      _builder_1.append("   ");
      _builder_1.append("\"-//W3C//DTD XHTML 1.0 Transitional//EN\"");
      _builder_1.newLine();
      _builder_1.append("   ");
      _builder_1.append("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("<html xmlns=\"http://www.w3.org/1999/xhtml\"");
      _builder_1.newLine();
      _builder_1.append("      ");
      _builder_1.append("xmlns:h=\"http://java.sun.com/jsf/html\">");
      _builder_1.newLine();
      _builder_1.append("      ");
      _builder_1.append("<h:head>");
      _builder_1.newLine();
      _builder_1.append("      \t");
      _builder_1.append("<title>");
      String _name = view.getName();
      _builder_1.append(_name, "      	");
      _builder_1.append("</title>");
      _builder_1.newLineIfNotEmpty();
      _builder_1.append("      ");
      _builder_1.append("</h:head>");
      _builder_1.newLine();
      _builder_1.append("      ");
      _builder_1.append("<h:body>");
      _builder_1.newLine();
      {
        EList<Form> _forms = view.getForms();
        int _size = _forms.size();
        boolean _equals_1 = (_size == 0);
        if (_equals_1) {
          _builder_1.append("\t\t");
          _builder_1.append("<p>Voici une page terminal !</p>");
          _builder_1.newLine();
        } else {
          {
            EList<Form> _forms_1 = view.getForms();
            for(final Form form : _forms_1) {
              _builder_1.append("\t\t");
              _builder_1.append("<p>");
              String _name_1 = form.getName();
              _builder_1.append(_name_1, "		");
              _builder_1.append("</p>");
              _builder_1.newLineIfNotEmpty();
              _builder_1.append("\t\t");
              _builder_1.append("<p>  #{");
              String _name_2 = view.getName();
              String _firstLower = StringExtensions.toFirstLower(_name_2);
              _builder_1.append(_firstLower, "		");
              _builder_1.append("Controller.");
              String _name_3 = form.getName();
              String _firstLower_1 = StringExtensions.toFirstLower(_name_3);
              _builder_1.append(_firstLower_1, "		");
              _builder_1.append("Error} </p>");
              _builder_1.newLineIfNotEmpty();
              _builder_1.append("\t\t");
              _builder_1.append("<h:form>");
              _builder_1.newLine();
              {
                EList<AssignedField> _assignedFields = form.getAssignedFields();
                for(final AssignedField assignedField : _assignedFields) {
                  _builder_1.append("\t\t");
                  _builder_1.append("\t");
                  String _fieldName = assignedField.getFieldName();
                  _builder_1.append(_fieldName, "			");
                  _builder_1.append(": <h:inputText value=\"#{");
                  String _name_4 = view.getName();
                  String _firstLower_2 = StringExtensions.toFirstLower(_name_4);
                  _builder_1.append(_firstLower_2, "			");
                  _builder_1.append("Controller.");
                  String _fieldName_1 = assignedField.getFieldName();
                  _builder_1.append(_fieldName_1, "			");
                  _builder_1.append("}\" /> <br/>");
                  _builder_1.newLineIfNotEmpty();
                }
              }
              _builder_1.append("\t\t");
              _builder_1.append("\t");
              _builder_1.append("<h:commandButton value=\"validate\" action=\"#{");
              String _name_5 = view.getName();
              String _firstLower_3 = StringExtensions.toFirstLower(_name_5);
              _builder_1.append(_firstLower_3, "			");
              _builder_1.append("Controller.validate");
              String _name_6 = view.getName();
              String _firstUpper = StringExtensions.toFirstUpper(_name_6);
              _builder_1.append(_firstUpper, "			");
              String _name_7 = form.getName();
              String _firstUpper_1 = StringExtensions.toFirstUpper(_name_7);
              _builder_1.append(_firstUpper_1, "			");
              _builder_1.append("}\" />");
              _builder_1.newLineIfNotEmpty();
              _builder_1.append("\t\t");
              _builder_1.append("</h:form>");
              _builder_1.newLine();
            }
          }
        }
      }
      _builder_1.append("      ");
      _builder_1.append("</h:body>");
      _builder_1.newLine();
      _builder_1.append("</html>");
      _builder_1.newLine();
      fileContent = _builder_1;
    }
    String _name_8 = modelMVCContainer.getName();
    String _plus_1 = (_name_8 + "Jsf/WebContent/");
    String _name_9 = view.getName();
    String _plus_2 = (_plus_1 + _name_9);
    String _plus_3 = (_plus_2 + ".xhtml");
    fsa.generateFile(_plus_3, fileContent);
  }
}
